package pikes.ecma;

public class ReturnStatement extends PrintableSourceElement implements Statement {

	private IExpression expression = null;

	public ReturnStatement() {

	}

	public ReturnStatement(IExpression expression) {
		this.expression = expression;
	}

	public void visit(SyntaxTreeVisitor syntaxTreeVisitor) throws EcmaSyntaxVisitingException {
		syntaxTreeVisitor.Return();
		if (expression != null) {
			syntaxTreeVisitor.whiteSpace();
			expression.visit(syntaxTreeVisitor);
		}
		syntaxTreeVisitor.endOfStatement();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof ReturnStatement) {
			ReturnStatement rs = (ReturnStatement) obj;
			if (expression == null) {
				return rs.expression == null;
			}
			else {
				return expression.equals(rs.expression);
			}
		}
		return false;
	}

	@Override
	public int hashCode() {
		if (expression != null) {
			return expression.hashCode();
		}
		return getClass().hashCode();
	}

}
